/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.breeze.generator;

import com.breeze.parser.DefaultParser;
import com.breeze.util.ColumnData;
import com.breeze.util.StringUtil;
import java.util.List;

/**
 *
 * @author huateng
 */
public class JavaFileGenerator  extends DefaultFileGenerator{


    @Override
    public String generate(List<ColumnData> dataList) {
        StringBuilder sb=new StringBuilder();
        String pack=DefaultParser.getProperties("package");
        
        sb.append("package ").append(pack).append(";\n\n");
        sb.append("public class ").append(StringUtil.getString(StringUtil.getHumpString(getTableName().toLowerCase()))).append("{\r\n\r\n");
        for(int i=0;i<dataList.size();i++){
            ColumnData tmp=dataList.get(i);
            sb.append("private ");
            sb.append(tmp.getClassName());
            sb.append(" ").append(tmp.getHumpName());
            sb.append(";\r\n");
        }
        
        sb.append("\r\n");
        for(int i=0;i<dataList.size();i++){
            ColumnData tmp=dataList.get(i);
            sb.append("public void ");
            sb.append(StringUtil.getSetString(tmp.getHumpName()));
            sb.append("(").append(tmp.getClassName()).append(" arg){\r\n");
            sb.append("this.").append(tmp.getHumpName()).append("=arg;\r\n");
            sb.append("}\r\n\r\n");
            
            sb.append("public ").append(tmp.getClassName()).append(" ").append(StringUtil.getGetString(tmp.getHumpName())).append("(){\r\n");
            sb.append("return this.").append(tmp.getHumpName()).append(";\r\n");
            sb.append("}\r\n\r\n");
        }
        
        sb.append("\r\n}");
        return sb.toString();
    }

    public String getFileName() {
        return StringUtil.getHumpStringString(getTableName())+".java";
    }
    
}
